{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Min Max Game"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: minMaxGame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #极大极小游戏"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ，其长度是 <code>2</code> 的幂。</p>\n",
    "\n",
    "<p>对 <code>nums</code> 执行下述算法：</p>\n",
    "\n",
    "<ol>\n",
    "\t<li>设 <code>n</code> 等于 <code>nums</code> 的长度，如果 <code>n == 1</code> ，<strong>终止</strong> 算法过程。否则，<strong>创建</strong> 一个新的整数数组&nbsp;<code>newNums</code> ，新数组长度为 <code>n / 2</code> ，下标从 <strong>0</strong> 开始。</li>\n",
    "\t<li>对于满足&nbsp;<code>0 &lt;= i &lt; n / 2</code> 的每个 <strong>偶数</strong> 下标 <code>i</code> ，将 <code>newNums[i]</code> <strong>赋值</strong> 为 <code>min(nums[2 * i], nums[2 * i + 1])</code> 。</li>\n",
    "\t<li>对于满足&nbsp;<code>0 &lt;= i &lt; n / 2</code> 的每个 <strong>奇数</strong> 下标 <code>i</code> ，将 <code>newNums[i]</code> <strong>赋值</strong> 为 <code>max(nums[2 * i], nums[2 * i + 1])</code> 。</li>\n",
    "\t<li>用 <code>newNums</code> 替换 <code>nums</code> 。</li>\n",
    "\t<li>从步骤 1 开始 <strong>重复</strong> 整个过程。</li>\n",
    "</ol>\n",
    "\n",
    "<p>执行算法后，返回 <code>nums</code> 中剩下的那个数字。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/04/13/example1drawio-1.png\" style=\"width: 500px; height: 240px;\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,3,5,2,4,8,2,2]\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>重复执行算法会得到下述数组。\n",
    "第一轮：nums = [1,5,4,2]\n",
    "第二轮：nums = [1,4]\n",
    "第三轮：nums = [1]\n",
    "1 是最后剩下的那个数字，返回 1 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [3]\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>3 就是最后剩下的数字，返回 3 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 1024</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>nums.length</code> 是 <code>2</code> 的幂</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [min-max-game](https://leetcode.cn/problems/min-max-game/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [min-max-game](https://leetcode.cn/problems/min-max-game/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,3,5,2,4,8,2,2]', '[3]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "\n",
    "        while n != 1:\n",
    "            n //= 2\n",
    "            for i in range(n):\n",
    "                if i & 1:\n",
    "                    nums[i] = max(nums[2*i], nums[2*i+1])\n",
    "                else:\n",
    "                    nums[i] = min(nums[2*i], nums[2*i+1])\n",
    "            \n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while (n := len(nums)) > 1:\n",
    "            nums2 = [0] * (n >> 1)\n",
    "            for i in range(n >> 1):\n",
    "                if i & 1:\n",
    "                    nums2[i] = max(nums[i << 1], nums[i * 2 + 1])\n",
    "                else:\n",
    "                    nums2[i] = min(nums[i << 1], nums[i * 2 + 1])\n",
    "            nums = nums2\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums:[int]) -> int:\n",
    "        while True:\n",
    "            if len(nums) == 1:\n",
    "                break\n",
    "            else:\n",
    "                newNums = [i for i in range(int((len(nums))/2))]\n",
    "                for i in range(int(len(nums)/2)):\n",
    "                    if i % 2 == 0:\n",
    "                        newNums[i] = min(nums[2*i],nums[2*i+1])\n",
    "                    else:\n",
    "                        newNums[i] = max(nums[2*i],nums[2*i+1])\n",
    "            nums = newNums\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "     while (len(nums)>1):\n",
    "        n=len(nums)\n",
    "        newNums=[0]*(n//2)\n",
    "        for i in [x for x in range (n) if x %2==0 and x< (n//2)]:\n",
    "            newNums[i]=min(nums[2*i],nums[2*i+1])\n",
    "        for i in [x for x in range (n) if x%2!=0 and x< (n//2)]:\n",
    "            newNums[i]=max(nums[2*i],nums[2*i+1])\n",
    "        nums=newNums\n",
    "     else:\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        while n!=1:\n",
    "            n=n//2\n",
    "            new=[0]*n\n",
    "            for i in range(0,n,2):\n",
    "                new[i]=min(nums[2*i],nums[2*i+1])\n",
    "            for i in range(1,n,2):\n",
    "                new[i]=max(nums[2*i],nums[2*i+1])\n",
    "            nums=new\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) != 1:\n",
    "            new = []\n",
    "            for i in range(len(nums) // 2):\n",
    "                if i % 2 == 0:\n",
    "                    new.append(min(nums[2 * i], nums[2 * i + 1]))\n",
    "                else:\n",
    "                    new.append(max(nums[2 * i], nums[2 * i + 1]))\n",
    "            \n",
    "            nums = new\n",
    "\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        pre = nums \n",
    "        while len(pre) > 1:\n",
    "            nl = len(pre) // 2\n",
    "            new = [0] * nl\n",
    "            for i in range(nl):\n",
    "                if i % 2== 0:\n",
    "                    new[i] = min(pre[i*2], pre[i*2+1])\n",
    "                else:\n",
    "                    new[i] = max(pre[i*2], pre[i*2+1])\n",
    "            pre = new \n",
    "        return pre[0] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [0] * (n // 2)\n",
    "        for i in range(n // 2):\n",
    "            if i % 2 == 0:\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(newNums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [0] * (n // 2)\n",
    "        for i in range(n // 2):\n",
    "            if i % 2 == 0:\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(newNums)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums)>1:\n",
    "            list1 =[]\n",
    "            for i in range(0,len(nums)//2):\n",
    "                if i%2==0:\n",
    "                    list1.append(min(nums[i*2],nums[i*2+1]))\n",
    "                else:\n",
    "                    list1.append(max(nums[i*2],nums[i*2+1]))\n",
    "            nums=list1\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums)==1:\n",
    "            return nums[0]\n",
    "        newnums=[0]*(len(nums)//2)\n",
    "        for i in range(len(nums)//2):\n",
    "            if i%2==0:\n",
    "                newnums[i]=min(nums[2*i],nums[2*i+1])\n",
    "            else:\n",
    "                newnums[i]=max(nums[2*i],nums[2*i+1])\n",
    "        return self.minMaxGame(newnums)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums)>1:\n",
    "            i=0\n",
    "            newnums=[0]*(len(nums)//2)\n",
    "            while i<len(nums)/2:\n",
    "                if i%2==0:\n",
    "                    newnums[i]=min(nums[2*i],nums[2*i+1])\n",
    "                else:\n",
    "                    newnums[i]=max(nums[2*i],nums[2*i+1])\n",
    "                i+=1\n",
    "            nums=newnums\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            newNums = []\n",
    "            for num in range(int(len(nums)/2)):\n",
    "                if num % 2 ==0:\n",
    "                    newNums.append(min(nums[2*num],nums[2*num+1]))\n",
    "                elif num % 2 ==1:\n",
    "                    newNums.append(max(nums[2*num],nums[2*num+1]))\n",
    "\n",
    "            nums = newNums\n",
    "\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        while n>>1:\n",
    "            flag=1\n",
    "            tmp=[]\n",
    "            for j in range(0,len(nums),2):\n",
    "                v=min(nums[j],nums[j+1]) if flag else max(nums[j],nums[j+1])\n",
    "                tmp.append(v)\n",
    "                flag^=1\n",
    "            nums=tmp\n",
    "            tmp=[]\n",
    "            n>>=1\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        new_nums = nums\n",
    "        while n > 1:\n",
    "            new_nums = [None]*int((n/2))\n",
    "            for i in range(len(new_nums)):\n",
    "                if i%2 == 0:\n",
    "                    new_nums[i] = min(nums[2*i],nums[2*i+1])\n",
    "                else:\n",
    "                    new_nums[i] = max(nums[2*i],nums[2*i+1])\n",
    "            n = n/2\n",
    "            nums = new_nums\n",
    "        return new_nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            n >>= 1\n",
    "            for i in range(n):\n",
    "                a, b = nums[i << 1], nums[i << 1 | 1]\n",
    "                if i % 2 == 0:\n",
    "                    nums[i] = min(a, b)\n",
    "                else :\n",
    "                    nums[i]=max(a, b)\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) != 1:\n",
    "            tmp = []\n",
    "            f = 0\n",
    "            for i in range(0,len(nums),2):\n",
    "                if not f:\n",
    "                    tmp.append(min(nums[i],nums[i + 1]))\n",
    "                else:\n",
    "                    tmp.append(max(nums[i],nums[i + 1]))\n",
    "                f ^= 1\n",
    "            nums = tmp\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while (n := len(nums)) > 1:\n",
    "            n >>= 1\n",
    "            for i in range(n):\n",
    "                if i & 1:\n",
    "                    nums[i] = max(nums[i << 1], nums[i * 2 + 1])\n",
    "                else:\n",
    "                    nums[i] = min(nums[i << 1], nums[i * 2 + 1])\n",
    "            nums = nums[:n]\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while (n := len(nums)) > 1:\n",
    "            new_len = n >> 1\n",
    "            for i in range(new_len):\n",
    "                if i & 1:\n",
    "                    nums[i] = max(nums[i << 1], nums[i * 2 + 1])\n",
    "                else:\n",
    "                    nums[i] = min(nums[i << 1], nums[i * 2 + 1])\n",
    "            nums = nums[:new_len]\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n != 1:\n",
    "            new = [0] * n\n",
    "            for i in range(n//2):\n",
    "                if i %2==0:\n",
    "                    new[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "                else:    \n",
    "                    new[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums = new\n",
    "            n = n//2\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            tmp_nums = []\n",
    "            for i in range(len(nums) // 2):\n",
    "                if i % 2 == 0:\n",
    "                    tmp_nums.append(min(nums[2 * i], nums[2 * i + 1]))\n",
    "                else:\n",
    "                    tmp_nums.append(max(nums[2 * i], nums[2 * i + 1]))\n",
    "            nums = tmp_nums\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums)!=1:\n",
    "            n = len(nums)\n",
    "            newNums = [0]*(n//2)\n",
    "            for i in range(n//2):\n",
    "                if i%2==0:\n",
    "                    newNums[i] = min(nums[2*i],nums[2*i+1])\n",
    "                else:\n",
    "                    newNums[i] = max(nums[2*i],nums[2*i+1])\n",
    "            nums = newNums\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n!=1:\n",
    "            x = 0\n",
    "            tem=[]\n",
    "            for i in range(0,len(nums),2):\n",
    "                if x%2==0:\n",
    "                    tem.append(min(nums[i],nums[i+1]))\n",
    "                else:\n",
    "                    tem.append(max(nums[i],nums[i+1]))\n",
    "                x+=1\n",
    "            nums = tem\n",
    "            n = len(nums)\n",
    "        return nums[0]\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            n >>= 1\n",
    "            for i in range(n):\n",
    "                a, b = nums[i << 1], nums[i << 1 | 1]\n",
    "                nums[i] = min(a, b) if i % 2 == 0 else max(a, b)\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            n >>= 1\n",
    "            for i in range(n):\n",
    "                a, b = nums[i << 1], nums[i << 1 | 1]\n",
    "                nums[i] = min(a, b) if i % 2 == 0 else max(a, b)\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            flag = 1\n",
    "            res = []\n",
    "            for i in range(0, len(nums)-1, 2): \n",
    "                if flag == 1:\n",
    "                    res.append(min(nums[i], nums[i+1]))\n",
    "                else:\n",
    "                    res.append(max(nums[i], nums[i+1]))\n",
    "                flag *= -1\n",
    "            nums = res\n",
    "        return nums[0]              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [None] * (n//2)\n",
    "        for i in range(n//2):\n",
    "            newNums[i] = min(nums[2 * i], nums[2 * i + 1]) if i % 2 == 0 else max(nums[2 * i], nums[2 * i + 1])\n",
    "        nums = newNums\n",
    "        return self.minMaxGame(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "      while len(nums) > 1:\n",
    "        newNums = []\n",
    "        i = 0\n",
    "        while i < (len(nums) // 2):\n",
    "          if i % 2 == 0:\n",
    "            newNums.append(min(nums[2*i], nums[2*i+1]))\n",
    "          else:\n",
    "            newNums.append(max(nums[2*i], nums[2*i+1]))\n",
    "          i += 1\n",
    "        nums = newNums[:]\n",
    "      return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [0] * (n // 2)\n",
    "        for i in range(n // 2):\n",
    "            if i % 2 == 0:\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(newNums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while nums.__len__() > 1:\n",
    "            new_length = nums.__len__() // 2\n",
    "            newnums = [0] * new_length\n",
    "            for i in range(new_length):\n",
    "                if i % 2 == 0:\n",
    "                    newnums[i] = min(nums[2*i], nums[2*i+1])\n",
    "                else:\n",
    "                    newnums[i] = max(nums[2*i], nums[2*i+1])\n",
    "            nums = newnums\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            ans = []\n",
    "            for i in range(0, n, 2):\n",
    "                if (i // 2) % 2 == 0:\n",
    "                    ans.append(min(nums[i], nums[i + 1]))\n",
    "                else:\n",
    "                    ans.append(max(nums[i], nums[i + 1]))\n",
    "            nums = ans\n",
    "            n >>= 1\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            t = []\n",
    "            for i in range(0,len(nums),2):\n",
    "                if not (i // 2) % 2:\n",
    "                    t.append(min(nums[i],nums[i+1]))\n",
    "                else:\n",
    "                    t.append(max(nums[i],nums[i+1]))\n",
    "            nums = t\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while True:\n",
    "            for i in range(0,len(nums),4):\n",
    "                if i+1<len(nums):                    \n",
    "                    nums[i]=min(nums[i+1],nums[i])\n",
    "                    nums[i+1]=None\n",
    "                if i+3<len(nums):                    \n",
    "                    nums[i+2]=max(nums[i+3],nums[i+2])\n",
    "                    nums[i+3]=None\n",
    "            #print(1,nums)\n",
    "            for i in range(len(nums)-1,-1,-1):\n",
    "                if nums[i]==None:\n",
    "                    nums.pop(i)\n",
    "            #print(2,nums)\n",
    "            if len(nums)==1:\n",
    "                return nums[0]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            ans = [min(nums[i], nums[i + 1]) if (i // 2) % 2 == 0 else\n",
    "                   max(nums[i], nums[i + 1]) for i in range(0, n, 2)]\n",
    "            nums = ans\n",
    "            n >>= 1\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        if n==1:\n",
    "            return nums[0]\n",
    "        n=n//2\n",
    "        new=[0]*n\n",
    "        for i in range(0,n,2):\n",
    "            new[i]=min(nums[2*i],nums[2*i+1])\n",
    "        for i in range(1,n,2):\n",
    "            new[i]=max(nums[2*i],nums[2*i+1])\n",
    "        nums=new\n",
    "        return self.minMaxGame(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        n = len(nums)\n",
    "        while (n := len(nums)) != 1:\n",
    "            for i in range(n//2):\n",
    "                if i % 2 == 0:\n",
    "                    nums[i] = min(nums[i*2],nums[i*2+1])\n",
    "                else:\n",
    "                    nums[i] = max(nums[i*2],nums[i*2+1])\n",
    "            nums = nums[:n//2] \n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        def out(s):\n",
    "            n=len(s)\n",
    "            k=1\n",
    "            for i in range(0,len(s)-1,2):\n",
    "                k=-k\n",
    "                if k ==-1:\n",
    "                    s.append(min(s[i],s[i+1]))\n",
    "                else:s.append(max(s[i],s[i+1]))\n",
    "            return s[n::]\n",
    "        while len(nums)!=1:\n",
    "            nums=out(nums)\n",
    "        return nums[0]\n",
    "    \t\n",
    "        \n",
    "                \n",
    "                    \n",
    "                \n",
    "                \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        for i in range(len(nums) // 2):\n",
    "            if i % 2 == 0:\n",
    "                nums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                nums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(nums[:len(nums) // 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            n = len(nums) // 2\n",
    "            newNums = [0] * n\n",
    "            for i in range(n):\n",
    "                if i % 2 ==0:\n",
    "                    newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "                else:\n",
    "                    newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums = newNums\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n != 1:\n",
    "            n = int(n / 2)\n",
    "            newNums = [0] * n\n",
    "            for i in range(n):\n",
    "                if i % 2 == 0:\n",
    "                    newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "                else:\n",
    "                    newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums = newNums\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            newNums = []\n",
    "            for i in range(0, len(nums) // 2):\n",
    "                if i % 2 == 0:  # 偶数下标\n",
    "                    newNums.append(min(nums[2 * i], nums[2 * i + 1]))\n",
    "                else:  # 奇数下标\n",
    "                    newNums.append(max(nums[2 * i], nums[2 * i + 1]))\n",
    "            nums = newNums  # 用 newNums 替换 nums\n",
    "        return nums[0]\n",
    "\n",
    "# 测试\n",
    "s = Solution()\n",
    "nums = [2,3,5,8,6,7,4,1]\n",
    "print(s.minMaxGame(nums))  # 应该返回符合你描述的结果\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        #递归\n",
    "        # n = len(nums)\n",
    "        # if n==1:\n",
    "        #     return nums[0]\n",
    "        # newnums = [0]*(n//2)\n",
    "        # for i in range(n//2):\n",
    "        #     if i%2==0:\n",
    "        #         newnums[i] = min(nums[2*i],nums[2*i+1])\n",
    "\n",
    "        #     else:\n",
    "        #         newnums[i] = max(nums[2*i],nums[2*i+1])\n",
    "        # return self.minMaxGame(newnums)\n",
    "        \n",
    "        #原地\n",
    "        n = len(nums)\n",
    "        while n!=1:\n",
    "            n //=2\n",
    "            for i in range(n):\n",
    "                if i%2==0:\n",
    "                    nums[i]= min(nums[2*i],nums[2*i+1])\n",
    "                else:\n",
    "                    nums[i] = max(nums[2*i],nums[2*i+1])\n",
    "        return nums[0]\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        n = len(nums)\n",
    "        while (n := len(nums)) != 1:\n",
    "            for i in range(n//2):\n",
    "                if i % 2 == 0:\n",
    "                    nums[i] = min(nums[i*2],nums[i*2+1])\n",
    "                else:\n",
    "                    nums[i] = max(nums[i*2],nums[i*2+1])\n",
    "            nums = nums[:n//2] \n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while (n := len(nums)) > 1:\n",
    "            new_len = n >> 1\n",
    "            nums2 = [0] * new_len\n",
    "            for i in range(new_len):\n",
    "                if i & 1:\n",
    "                    nums[i] = max(nums[i << 1], nums[i * 2 + 1])\n",
    "                else:\n",
    "                    nums[i] = min(nums[i << 1], nums[i * 2 + 1])\n",
    "            nums = nums[:new_len]\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        \n",
    "        while len(nums)!=1:\n",
    "\n",
    "            n=len(nums)\n",
    "            newnum=[0]*(n//2)\n",
    "            f=0\n",
    "            for i in range(n//2):\n",
    "                if i%2==0:\n",
    "                    newnum[i]=min(nums[2 * i], nums[2 * i + 1])\n",
    "                else:\n",
    "                    newnum[i]=max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums=newnum\n",
    "        \n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        n = len(nums)\n",
    "        while n != 1:\n",
    "            for i in range(n//2):\n",
    "                if i % 2 == 0:\n",
    "                    nums[i] = min(nums[i*2],nums[i*2+1])\n",
    "                else:\n",
    "                    nums[i] = max(nums[i*2],nums[i*2+1])\n",
    "            nums = nums[:n//2]\n",
    "            n = len(nums) \n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while True:\n",
    "            if len(nums)==1:\n",
    "                break\n",
    "            x=[]\n",
    "            n=len(nums)\n",
    "            for i in range(n//2):\n",
    "                if i%2==0:\n",
    "                    x.append(min(nums[2*i],nums[2*i+1]))\n",
    "                else:\n",
    "                    x.append(max(nums[2*i],nums[2*i+1]))\n",
    "            nums=x\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) > 1:\n",
    "            return self.minMaxGame([min(nums[i], nums[i+1]) if i // 2 % 2 == 0 else max(nums[i], nums[i+1]) for i in range(0, len(nums), 2)])\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [0] * (n // 2)\n",
    "        for i in range(n // 2):\n",
    "            if i % 2 == 0:\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(newNums)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            nums = [min(nums[i], nums[i + 1]) if (i // 2) % 2 == 0 else\n",
    "                    max(nums[i], nums[i + 1]) for i in range(0, n, 2)]\n",
    "            n >>= 1\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) > 1:\n",
    "            newNums = []\n",
    "            for i in range(0, len(nums) // 2):\n",
    "                if i % 2 == 0:  # 偶数下标\n",
    "                    newNums.append(min(nums[2 * i], nums[2 * i + 1]))\n",
    "                else:  # 奇数下标\n",
    "                    newNums.append(max(nums[2 * i], nums[2 * i + 1]))\n",
    "            nums = newNums  # 用 newNums 替换 nums\n",
    "        return nums[0]\n",
    "\n",
    "# # 测试\n",
    "# s = Solution()\n",
    "# nums = [2,3,5,8,6,7,4,1]\n",
    "# print(s.minMaxGame(nums))  # 应该返回符合你描述的结果\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        # 按题意模拟\n",
    "        # n = len(nums)\n",
    "        # while n > 1:\n",
    "        #     n2 = n//2\n",
    "        #     newNums = [0]*n2\n",
    "        #     for i in range(n2):\n",
    "        #         # print(i)\n",
    "        #         if i % 2 == 0 and (2*i+1)<=n:\n",
    "        #             newNums[i] = min(nums[2*i], nums[2*i+1])\n",
    "        #         elif i%2 !=0 and (2*i+1)<=n:\n",
    "        #             newNums[i] = max(nums[2*i], nums[2*i+1])\n",
    "        #     nums = newNums\n",
    "        #     n = len(nums)\n",
    "        # return nums[0]\n",
    "\n",
    "\n",
    "        # 官解：递归\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [0]*(n//2)\n",
    "        for i in range(n//2):\n",
    "            if i%2 == 0:\n",
    "                newNums[i]=min(nums[2*i], nums[2*i+1])\n",
    "            else:\n",
    "                newNums[i]=max(nums[2*i], nums[2*i+1])\n",
    "        return self.minMaxGame(newNums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        newNums = [0] * (n // 2)\n",
    "        for i in range(n // 2):\n",
    "            if i % 2 == 0:\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(newNums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        Q = deque(nums)\n",
    "        while len(Q) > 1:\n",
    "            l = len(Q)\n",
    "            for i in range(l//2):\n",
    "                a, b = Q.popleft(), Q.popleft()\n",
    "                if i % 2 == 0:\n",
    "                    Q.append(min(a,b))\n",
    "                else:\n",
    "                    Q.append(max(a,b))\n",
    "        return Q[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        def iter(nums):\n",
    "            n = len(nums)\n",
    "            newNums = [None] * (n//2)\n",
    "            for i in range(n//2):\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1]) if i % 2 == 0 else max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums = newNums\n",
    "            return nums\n",
    "        \n",
    "        while len(nums) != 1:\n",
    "            nums = iter(nums)\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums) !=1:\n",
    "            newNums = [0]*(len(nums)//2)\n",
    "            for i in range(len(newNums)):\n",
    "                if i%2==0:\n",
    "                    newNums[i]=min(nums[2 * i], nums[2 * i + 1])\n",
    "                else:\n",
    "                    newNums[i]=max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums[:]=newNums\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        n = len(nums)\n",
    "        while n != 1:\n",
    "            temp = [0] * (n//2)\n",
    "            for i in range(n//2):\n",
    "                if i % 2 == 0:\n",
    "                    temp[i] = min(nums[i*2],nums[i*2+1])\n",
    "                else:\n",
    "                    temp[i] = max(nums[i*2],nums[i*2+1])\n",
    "            nums = temp\n",
    "            n = len(nums) \n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        for i in range(n // 2):\n",
    "            if i % 2 == 0:\n",
    "                nums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                nums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        nums = nums[:n // 2]\n",
    "        return self.minMaxGame(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        while len(nums)>1:\n",
    "            ans=[0]*(len(nums)//2)\n",
    "            print(ans)\n",
    "            for i in range(len(ans)):\n",
    "                if i%2:\n",
    "                    ans[i]=max(nums[2*i],nums[2*i+1])\n",
    "                else:\n",
    "                    ans[i]=min(nums[2*i],nums[2*i+1])\n",
    "            nums=ans\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        \n",
    "        while len(nums) > 1:\n",
    "            arr = []\n",
    "            n = len(nums)\n",
    "            for i in range(n//2):\n",
    "                if i %2:\n",
    "                    arr.append(max(nums[2*i], nums[2*i+1]))\n",
    "                else:\n",
    "                    arr.append(min(nums[2*i], nums[2*i+1]))\n",
    "            nums = arr[:]\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        l=len(nums)\n",
    "        while(l>1):\n",
    "            for i in range(l//2):\n",
    "                if i%2==0:\n",
    "                    nums[i]=min(nums[2*i],nums[2*i+1])\n",
    "                else:\n",
    "                    nums[i]=max(nums[2*i],nums[2*i+1])\n",
    "            l//=2\n",
    "        print(nums)\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\r\n",
    "        while len(nums) != 1:\r\n",
    "            newNums = [0]*(int(len(nums)/2))\r\n",
    "            for i in range(int(len(nums)/2)):\r\n",
    "                if i%2 == 0:\r\n",
    "                    newNums[i] = min(nums[2 * i], nums[2 * i + 1]) \r\n",
    "                else:\r\n",
    "                    newNums[i] = max(nums[2 * i], nums[2 * i + 1]) \r\n",
    "            nums = newNums\r\n",
    "        \r\n",
    "        return nums[0]\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        ans = nums\n",
    "        while len(ans) > 1:\n",
    "            nxt = []\n",
    "            for i in range(len(ans) >> 1):\n",
    "                if i % 2 == 0:\n",
    "                    nxt.append(min(ans[2 * i], ans[2 * i + 1]))\n",
    "                else:\n",
    "                    nxt.append(max(ans[2 * i], ans[2 * i + 1]))\n",
    "            ans = nxt\n",
    "        return ans[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\r\n",
    "        n = len(nums)\r\n",
    "        if n == 1:\r\n",
    "            return nums[0]\r\n",
    "        newNums = []\r\n",
    "        for i in range(n//2):\r\n",
    "            if i%2 == 0:\r\n",
    "                newNums.append(min(nums[2*i], nums[2*i+1]))\r\n",
    "            else:\r\n",
    "                newNums.append(max(nums[2*i], nums[2*i+1]))\r\n",
    "        return self.minMaxGame(newNums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        while n > 1:\n",
    "            for i in range(n // 2):\n",
    "                if i & 1 == 0:\n",
    "                    nums[i] = min(nums[i * 2], nums[i * 2 + 1])\n",
    "                else:\n",
    "                    nums[i] = max(nums[i * 2], nums[i * 2 + 1])\n",
    "            n >>= 1\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return nums[0]\n",
    "        \n",
    "        newNums = [0] * int(n/2)\n",
    "        for i in range(int(n/2)):\n",
    "            if i%2 == 0:\n",
    "                newNums[i] = min(nums[2 * i], nums[2 * i + 1])\n",
    "            else:\n",
    "                newNums[i] = max(nums[2 * i], nums[2 * i + 1])\n",
    "        return self.minMaxGame(newNums)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        while n//2>0:\n",
    "            n//=2\n",
    "            newNums=[None]*n\n",
    "            for i in range(n):\n",
    "                if i%2==0:\n",
    "                    newNums[i]=min(nums[2 * i], nums[2 * i + 1])\n",
    "                else:\n",
    "                    newNums[i]=max(nums[2 * i], nums[2 * i + 1])\n",
    "            nums=newNums.copy()\n",
    "        return nums[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        newNums=[]\n",
    "        while len(nums)!=1:\n",
    "            newNums.clear()\n",
    "            n=len(nums)\n",
    "            for i in range(0,n//2):\n",
    "                if i%2==0:\n",
    "                    newNums.append(min(nums[2*i],nums[2*i+1]))\n",
    "                else:\n",
    "                    newNums.append(max(nums[2*i],nums[2*i+1]))\n",
    "            nums=newNums[:]\n",
    "        return nums[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minMaxGame(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        n = len(nums)\n",
    "        while n != 1:\n",
    "            # temp = [0] * (n//2)\n",
    "            for i in range(n//2):\n",
    "                if i % 2 == 0:\n",
    "                    nums[i] = min(nums[i*2],nums[i*2+1])\n",
    "                else:\n",
    "                    nums[i] = max(nums[i*2],nums[i*2+1])\n",
    "            # nums = temp\n",
    "            nums = nums[:n//2]\n",
    "            n = len(nums) \n",
    "        return nums[0]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
